
package gui.panels;

import gui.MainFrame;
import gui.listeners.GuiActionEvent;
import gui.listeners.GuiActionEventType;
import gui.model.DrinkModel;
import gui.panels.components.MmiButton;
import java.awt.Insets;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JLabel;

/**
 *
 * @author JtR
 */
public class SelectSizePanel extends GuiPanel {
    private MmiButton smallButtonCoffee, mediumButtonCoffee, bigButtonCoffee;
    private MmiButton smallButtonTea, mediumButtonTea, bigButtonTea;
    private boolean isEspresso = false;
    
    public SelectSizePanel(MainFrame parent) {
        this(parent, false);
    }
    
    public SelectSizePanel(MainFrame parent, boolean isEspresso) {
        super(parent, null);
        this.isEspresso = isEspresso;
        initComponents(isEspresso);
    }
    
    private void initComponents(boolean isEspresso) {
        int offset = isEspresso ? 150 : 0;
        // Kaffee klein
        smallButtonCoffee = new MmiButton("res/kaffeepause/100ml.png", 150);
        smallButtonCoffee.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                fireGuiActionEvent(new GuiActionEvent(GuiActionEventType.CHOSE_SMALL));
            }
        });
        constraints.insets = new Insets(250, 122 + offset, 0, 0);
        add(smallButtonCoffee, constraints);
        
        // Tee klein
        smallButtonTea = new MmiButton("res/teetime/teeglas100.png", 150);
        smallButtonTea.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                fireGuiActionEvent(new GuiActionEvent(GuiActionEventType.CHOSE_SMALL));
            }
        });
        constraints.insets = new Insets(250, 122 + offset, 0, 0);
        add(smallButtonTea, constraints);
        
        // Kaffee mittel
        mediumButtonCoffee = new MmiButton("res/kaffeepause/200ml.png", 190);
        mediumButtonCoffee.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                fireGuiActionEvent(new GuiActionEvent(GuiActionEventType.CHOSE_MEDIUM));
            }
        });
        constraints.insets = new Insets(210, 400 + offset, 0, 0);
        add(mediumButtonCoffee, constraints);
        
        // Tee mittel
        mediumButtonTea = new MmiButton("res/teetime/teeglas200.png", 190);
        mediumButtonTea.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                fireGuiActionEvent(new GuiActionEvent(GuiActionEventType.CHOSE_MEDIUM));
            }
        });
        constraints.insets = new Insets(210, 400 + offset, 0, 0);
        add(mediumButtonTea, constraints);
        
        
        if(!isEspresso) {
            // Kaffee groß
            bigButtonCoffee = new MmiButton("res/kaffeepause/300ml.png", 230);
            bigButtonCoffee.addActionListener(new ActionListener() {
                @Override
                public void actionPerformed(ActionEvent e) {
                    fireGuiActionEvent(new GuiActionEvent(GuiActionEventType.CHOSE_BIG));
                }
            });
            constraints.insets = new Insets(170, 724, 0, 0);
            add(bigButtonCoffee, constraints);
        }
        // Tee groß
        bigButtonTea = new MmiButton("res/teetime/teeglas300.png", 230);
        bigButtonTea.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                fireGuiActionEvent(new GuiActionEvent(GuiActionEventType.CHOSE_BIG));
            }
        });
        constraints.insets = new Insets(170, 724, 0, 0);
        add(bigButtonTea, constraints);
    }

    @Override
    public String getDescription() {
        return "Bitte wählen Sie die Tassengröße";
    }

    @Override
    public void updateFields() {
        switch(DrinkModel.getInstance().getDrink()) {
            case COFFEE:
                smallButtonCoffee.setVisible(true);
                smallButtonTea.setVisible(false);
                mediumButtonCoffee.setVisible(true);
                mediumButtonTea.setVisible(false);
                if(!isEspresso) {
                    bigButtonCoffee.setVisible(true);
                }
                bigButtonTea.setVisible(false);
                backgroundType = BackgroundType.COFFEE;
                break;
            case TEA:
                smallButtonCoffee.setVisible(false);
                smallButtonTea.setVisible(true);
                mediumButtonCoffee.setVisible(false);
                mediumButtonTea.setVisible(true);
                if(!isEspresso) {
                    bigButtonCoffee.setVisible(false);
                }
                bigButtonTea.setVisible(true);
                backgroundType = BackgroundType.TEA;
                break;
        }
    }

    @Override
    public boolean getPreviousButtonEnabled() {
        return true;
    }

    @Override
    public boolean getNextButtonEnabled() {
        if(isEspresso) {
            return DrinkModel.getInstance().getSize()!= null;
        } else {
            return DrinkModel.getInstance().getSize()!= null;
        }
    }

    @Override
    public String getName() {
        if(isEspresso) {
            return "ESPRESSO_SIZE_NAME";
        } else {
            return "SIZE_NAME";
        }
    }

    @Override
    public GuiPanel getNextPanel() {
        if(!isEspresso) {
            if(DrinkModel.getInstance().getDrink() == DrinkModel.Drink.TEA) {
                return parent.selectBrewTimePanel;
            } else {
                return parent.selectBeansPanel;
            }
        } else {
            return parent.selectCoffeeAdditionsPanel;
        }
    }

    @Override
    public GuiPanel getPreviousPanel() {
        if(DrinkModel.getInstance().getDrink() == DrinkModel.Drink.COFFEE) {
            return parent.selectCoffeePanel;
        } else {
            return parent.selectTeaPanel;
        }
    }
}
